package com.mzj.saas.mservice.lock.Repository;

import com.mzj.saas.mservice.lock.entity.LockOpenLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface LockOpenLogRepository extends PagingAndSortingRepository<LockOpenLog,Long>, JpaSpecificationExecutor<LockOpenLog> {

    /**
     * 取开门时间最新的一条记录
     * @param userId
     * @return
     */
    @Query(value = "SELECT * FROM `saas_house_lock_open_log` WHERE user_id = ?1 order by open_time desc limit 1", nativeQuery = true)
    LockOpenLog findByUserId(Long userId);
}
